<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		  <#assign base=request.contextPath  />
		 <link rel="stylesheet" href="${base}/js/layui/css/layui.css" media="all">
		 <script type="text/javascript" src="${base}/js/zhang.js"></script>
		 <script src="${base}/js/layui/layui.js" charset="utf-8"></script>
         <script type="text/javascript" src="${base}/js/ztree/jquery-1.4.4.min.js"></script>
         <script src="${base}/js/jquery.min.js"></script>
	</head>
    <body>
    <div class="layui-upload">

        <div class="layui-upload-list">
            <table class="layui-table">
                <thead>
                <tr>
                    <th>文件名</th>
                    <th>大小</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="demoList">
                    <tr>
                        <th >
                            <a id="fileName"  ></a>
                        </th>
                    </tr>

                </tbody>
            </table>
        </div>
        <#--<button type="button" class="layui-btn layui-btn-primary" id="testList">选择文件</button>
        <button type="button" class="layui-btn layui-btn-normal" id="testListAction">开始上传</button>-->
        <form action="fileUpload" method="post" enctype="multipart/form-data">
            <p>选择文件: <input type="file" name="fileName"/></p>
            <p><input type="submit" value="提交"/></p>
        </form>
    </div>
    <script>
        layui.use('upload', function(){
            var $ = layui.jquery
                    ,upload = layui.upload;

            //多文件列表示例
            var demoListView = $('#demoList')
                    ,uploadListIns = upload.render({
                elem: '#testList'
                ,url: '${base}/motherNursing/selectWord'
                ,accept: 'file'
                ,multiple: true
                ,auto: false
                ,bindAction: '#testListAction'
                ,choose: function(obj){
                    var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                    //读取本地文件
                    obj.preview(function(index, file, result){
                        var tr = $(['<tr id="upload-'+ index +'">'
                            ,'<td>'+ file.name +'</td>'
                            ,'<td>'+ (file.size/1014).toFixed(1) +'kb</td>'
                            ,'<td>'
                            ,'<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                            ,'</td>'
                            ,'</tr>'].join(''));

                        //单个重传
                        tr.find('.demo-reload').on('click', function(){
                            obj.upload(index, file);
                        });

                        //删除
                        tr.find('.demo-delete').on('click', function(){
                            delete files[index]; //删除对应的文件
                            tr.remove();
                            uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                        });

                        demoListView.append(tr);
                    });
                }
            });
        });
    </script>
    <script>
        window.onload =function (){

          var aa = #{id};
            $.ajax({
                type:"get",
                url:"${base}/motherNursing/selectWord",
                datatype:"json",
                data:{"idd":aa},
                success:function (data) {
                    var fileName = data[0].fileName;//a.doc
                    var url  =  data[0].url;//D:\Users\Administrator\Desktop\新建文件夹\YueZi\uploads\a.doc
                    //alert(fileName);
                    //alert(url);
                    var a = document.getElementById("fileName");
                    a.onclick=function(){
                        $.ajax({
                            type:"post",
                            url:"http://localhost:8080/Zhang/motherNursing/editWord1",
                            data:{"fileName":fileName,"url":url},
                            success:function (data) {
                               window.location.href="http://localhost:8080/Zhang/motherNursing/editWord";
                            }
                        });
                    }
                    // a.href="?fileName="+fileName+"&url="+url;
                    a.innerText=fileName;
                }
            });



        }
    </script>
    </body>
</html>
